﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace yf倒计时
{
    public partial class Form2 : Form
    {
        bool fullscreen = false;
        Rectangle rect = new Rectangle();
        public Form2()
        {
           
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            this.TopMost = true;//弹出 显示在最顶层
            //////fullscreen = !fullscreen;//赋相反值 ，循环。点一次全屏，再点还原。   
            //////SetFullScreen(fullscreen, ref rect);
            //////if (fullscreen)
            //////{
            //////    this.FormBorderStyle = FormBorderStyle.None;

            //////    this.WindowState = FormWindowState.Maximized;//全屏   
            //////}
            //////else
            //////{
            //////    this.FormBorderStyle = FormBorderStyle.Sizable;

            //////    this.WindowState = FormWindowState.Normal;//还原   
            //////}

        }
        public static bool SetFullScreen(bool fullscreen, ref Rectangle rectOld)
        {
            int Hwnd = 0;
            Hwnd = FindWindow("Shell_TrayWnd", null);
            if (Hwnd == 0) return false;
            if (fullscreen)
            {
                ShowWindow(Hwnd, SW_HIDE);
                Rectangle rectFull = Screen.PrimaryScreen.Bounds;
                SystemParametersInfo(SPI_GETWORKAREA, 0, ref rectOld, SPIF_UPDATEINIFILE);//get   
                SystemParametersInfo(SPI_SETWORKAREA, 0, ref rectFull, SPIF_UPDATEINIFILE);//set   
            }
            else
            {
                ShowWindow(Hwnd, SW_SHOW);
                SystemParametersInfo(SPI_SETWORKAREA, 0, ref rectOld, SPIF_UPDATEINIFILE);
            }
            return true;
        }

        [DllImport("user32.dll", EntryPoint = "ShowWindow")]
        public static extern int ShowWindow(int hwnd, int nCmdShow);
        public const int SW_SHOW = 5; public const int SW_HIDE = 0;

        [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
        private static extern int SystemParametersInfo(int uAction, int uParam, ref Rectangle lpvParam, int fuWinIni);
        public const int SPIF_UPDATEINIFILE = 0x1;
        public const int SPI_SETWORKAREA = 47;
        public const int SPI_GETWORKAREA = 48;

        [DllImport("user32.dll", EntryPoint = "FindWindow")]
        private static extern int FindWindow(string lpClassName, string lpWindowName);

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
            this.TopMost = false;//
        }
    }
}
